package com.aiit.mapper;

import com.aiit.annotation.AutoFill;
import com.aiit.dto.EmployeePageQueryDTO;
import com.aiit.entity.Tea;
import com.aiit.entity.TeaOrder;
import com.aiit.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeaMapper {
    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Tea getByUsername(String username);

    Page<Tea> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);

    @AutoFill(value = OperationType.UPDATE)
    void update(Tea tea);

    /**
     * 插入员工数据
     *
     * @param tea
     */
    @Insert("insert into tea(name,type,price,remaining,create_time,update_time,status,photo)" +
            "values" +
            "(#{name},#{type},#{price},#{remaining},#{createTime},#{updateTime},#{status},#{photo})")
    @AutoFill(value = OperationType.INSERT)
    void insert(Tea tea);

    @Delete("delete from tea where name = #{name}")
    void deleteById(String name);

    List<Tea> list(Tea tea);

    @Insert("insert into orders(username,price,create_time,update_time,status,total_price,quantity,product_name)" +
            "values" +
            "(#{username},#{price},#{createTime},#{updateTime},#{status},#{totalPrice},#{quantity},#{productName})")
    @AutoFill(value = OperationType.INSERT)
    void insertOrder(TeaOrder teaOrder);

    @Update("UPDATE tea SET remaining = remaining - #{quantity} WHERE  name = #{productName}")
    void updateRemaining(TeaOrder teaOrder);


    @Update("UPDATE teacup SET remaining = remaining - #{quantity} WHERE  name = #{productName}")
    void updateRemaining2(TeaOrder teaOrder);
}
